package com.edmond.jyframe.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;

import com.edmond.jyframe.R;
import com.edmond.jyframe.activity.base.BaseActivity;
import com.edmond.jyframe.fragments.HomeFragment;
import com.edmond.jyframe.fragments.MineFragment;
import com.edmond.jyframe.fragments.ShoppingCartFragment;
import com.edmond.jyframe.fragments.ShowFragment;
import com.edmond.jyframe.presenter.base.NavPresenter;
import com.edmond.jyview.widget.JYFragmentPagerAdapter;
import com.edmond.jyview.widget.JYViewPager;

import java.util.ArrayList;

public class MainActivity extends BaseActivity<NavPresenter> {

    TabLayout tabLayout = null;
    JYViewPager viewPager = null;

    ArrayList<Fragment> fragments = new ArrayList<>();

    CardView bottomTab = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nav);

        bottomTab = (CardView) findViewById(R.id.bottom_tab_lay);
        tabLayout = (TabLayout) findViewById(R.id.bottom_tab);
        viewPager = (JYViewPager) findViewById(R.id.viewpager);

        fragments.add(new HomeFragment());
        fragments.add(new ShowFragment());
        fragments.add(new ShoppingCartFragment());
        fragments.add(new MineFragment());

        viewPager.setAdapter(new JYFragmentPagerAdapter(getSupportFragmentManager(),fragments));
        viewPager.setOffscreenPageLimit(3);

        TabLayout.Tab home = tabLayout.newTab();
        home.setCustomView(R.layout.tab_home);
        TabLayout.Tab show = tabLayout.newTab();
        show.setCustomView(R.layout.tab_show);
        TabLayout.Tab shoppingCart = tabLayout.newTab();
        shoppingCart.setCustomView(R.layout.tab_shopping_cart);
        TabLayout.Tab mine = tabLayout.newTab();
        mine.setCustomView(R.layout.tab_mine);

        tabLayout.addTab(home);
        tabLayout.addTab(show);
        tabLayout.addTab(shoppingCart);
        tabLayout.addTab(mine);

        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));

    }

    @Override
    public Class[] initModelName() {
        return new Class[0];
    }

}
